<?php
	//include("admin_check.inc.php");
	//include("config.inc.php");
	include("dbconnect.inc.php");
	if($_GET["ok"] == "1") $message="操作成功";
	if($_GET["do"] == "1") {
		$title = mysql_real_escape_string($_POST["title"]);
		$content =  mysql_real_escape_string($_POST["content"]);
		$category_id = $_POST["category_id"];
		$datetime = date("Y-m-d H:i:s");
		$sender = $_SESSION["username"];
		$message = "";
		if($title == "") {
			$message .= "新闻标题不能为空<br />";
		}
		if($content == "") {
			$message .= "新闻内容不能为空<br />";
		}		
		if(!is_numeric($category_id)) {
			$message .= "栏目错误<br />";
		}
		if($message == "") {
			$sql = "insert into news(news_title,news_content,news_sender,news_pubtime,news_index) ";
			$sql .= "values('{$title}','{$content}','{$sender}','{$datetime}',{$category_id}) ";
			if(mysql_query($sql)) {
				$message = "添加完成";
				$id = mysql_insert_id();
				header("Location:admin_editnews.php?id={$id}&ok=1");
			}else {
				$message = "添加失败，DB错误";
			}
		}
	}
?>
<?php include("header.inc.php"); ?>
<script type="text/javascript" src="../FCKeditor/fckeditor.js"></script>
<script type="text/javascript">
window.onload = function()
{
	var sBasePath = /FCKeditor/ ;
	var oFCKeditor = new FCKeditor( "content" ) ;
	oFCKeditor.BasePath	= sBasePath ;
	oFCKeditor.Width = "100%" ;
	oFCKeditor.Height = "400" ;
	oFCKeditor.ReplaceTextarea() ;
}
</script>
<table width="778" border="0" cellpadding="0" cellspacing="6" class="border">
  <tr> 
    <td valign="top" width="100%" class="listcontent" align="center"> 
          <b><?Php echo $message; ?></b>     
      <table width="100%" border="0" cellpadding="6" cellspacing="0">
        <tr> 
          <td class="listTitle"> 
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td><strong>添加新闻</strong></td><td align=right>&nbsp;</td>

                </tr>
            </table>
          </td>
        </tr>
        <tr> 
          <td valign="top" class="list"> 

			<form action="admin_addnews.php?do=1" method="post" >
				新闻标题：<input type="text" name="title" size="50" />&nbsp;
				选择栏目：
					<select name="category_id">
<?php
			$res = mysql_query("select * from new_class order by order_id ");
			while($row = mysql_fetch_array($res)) {
				echo "<option value='{$row['news_id']}'>{$row['nclass_name']}</option>";
			}
?>
					</select><br />
				新闻内容：<br />
				<textarea name="content" ></textarea><br /><br />
				<input type="submit" value="添　　加" />
			</form>

          </td>
        </tr>
      </table>
    </td>

  
  </tr>
</table>
<?php include("footer.inc.php"); ?>